package org.lanqiao.netctoss.controller.tariff;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.lanqiao.netctoss.entity.Tariff;
import org.lanqiao.netctoss.service.impl.TariffServiceImpl;

/**
 * Servlet implementation class DeleteFeeServlet
 */
public class DeleteFeeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteFeeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		//response.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("GBK");
		if(request.getParameter("start")!=null){
			int tar_no = Integer.parseInt(request.getParameter("start"));
			System.out.println("tar_no的值为："+tar_no);
			int tar_state = 1;
			/*boolean b = tariffBuss.updateTarStateByno(new Tariff(tar_no,tar_state));*/
			int i = new TariffServiceImpl().updateTarStateByno(new Tariff(tar_no,tar_state));
			if(i>0){
				PrintWriter out = response.getWriter();
				out.print("<script>alert('启用成功!');window.location.href='../tariff/FeeListServlet'</script>");
			}
			
		}
		if(request.getParameter("modify")!=null){
			int tar_no = Integer.parseInt(request.getParameter("modify"));
			/*List<Tariff> tt = tariffBuss.selectTariffByno(new Tariff(tar_no));*/
			List<Tariff> tt  = new TariffServiceImpl().selectTariffByno(new Tariff(tar_no));
			request.getSession().setAttribute("tt",tt);
			if(tt.size()!=-1){
				RequestDispatcher rd =request.getRequestDispatcher("../view/fee/fee_modi.jsp");
				rd.forward(request, response);	
			}
			
		}
		if(request.getParameter("delete")!=null){
			int tar_no = Integer.parseInt(request.getParameter("delete"));
			//boolean b = tariffBuss.delTariff(new Tariff(Integer.parseInt(request.getParameter("delete"))));
			int i = new TariffServiceImpl().delTariff(new Tariff(Integer.parseInt(request.getParameter("delete"))));
			if(i>0){
				PrintWriter out = response.getWriter();
				out.print("<script>alert('删除成功!');window.location.href='../tariff/FeeListServlet'</script>");
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
